package com.example.mp3player;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FileArrayAdapter extends ArrayAdapter<Option>{
	private Context ctx;
	private int id;
	private List<Option>items;

	public FileArrayAdapter(Context context, int textViewResourceId, List<Option> objects) {
		super(context, textViewResourceId, objects);
		ctx = context;
		id = textViewResourceId;
		items = objects;
	}

	public Option getItem(int i){
		return items.get(i);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(id, null);
		}

		final Option item = items.get(position);

		if (item != null) {
			TextView t1 = (TextView) v.findViewById(R.id.TextView01);
			TextView t2 = (TextView) v.findViewById(R.id.TextView02);
			ImageView i1 = (ImageView) v.findViewById(R.id.ImgView01);
			
			if(item.getName().endsWith(".mp3")){
				i1.setImageResource(R.drawable.mp3_file);
			}

			if(t1!=null)
				t1.setText(item.getName());
			if(t2!=null)
				t2.setText(item.getData());
		}
		return v;
	}
}
